package cookinmaddy.database.spod;

import cookinmaddy.model.Ingredient;

class DBIngredientManager  extends php.db.Manager<DBIngredient>
{

	public function new() 
	{
		super(DBIngredient);
	}
    override function make( c : DBIngredient ) : Void 
	{
		c.value = new Ingredient();
		c.value.ID = c.ing_id;
		c.value.Name = c.ing_name;
	}
  
    override function unmake( c : DBIngredient ) : Void 
	{
		c.ing_id = c.value.ID;
		c.ing_name = c.value.Name;
	}	

	
	public function fromId(id : Int) : Ingredient
	{
		var val : DBIngredient = DBIngredient.manager.get(id);
		var ret : Ingredient = new Ingredient();
		return val.value;
	}	
	
	public function allIngredients() : List<Ingredient>
	{
		var list : List<Ingredient> = new List<Ingredient>();
		var allvals = super.all();
		for (a in allvals)
		{
			list.add(a.value);
		}
		return list;
	}	
}